var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var goDeep = function (obj) {
    if (!(typeof obj === 'object'))
        return false;
    var typeList = [Date, RegExp, Array, Map, Set, Number, Boolean, String, Object];
    var resultType = '';
    for (var i = 0; i < typeList.length; i++) {
        var item = typeList[i];
        if (obj instanceof item) {
            resultType = item.name;
            break;
        }
    }
    return resultType === 'Array' || resultType === 'Object';
};
var clone = function (obj, isDeep) {
    if (isDeep === void 0) { isDeep = false; }
    if (!isDeep) {
        if (obj instanceof Array) {
            return __spreadArray([], obj, true);
        }
        if (obj instanceof Object) {
            return __assign({}, obj);
        }
    }
    if (obj instanceof Array) {
        var arr = [];
        for (var i = 0; i < obj.length; i++) {
            var item = obj[i];
            arr[i] = goDeep(item) ? clone(item, true) : item;
        }
        return arr;
    }
    if (obj instanceof Object) {
        var resultObj = {};
        for (var key in obj) {
            if (Object.prototype.hasOwnProperty.call(obj, key)) {
                var item = obj[key];
                resultObj[key] = goDeep(item) ? clone(item, true) : item;
            }
        }
        return resultObj;
    }
};
var testObj = {
    a: {
        b: [1, 2, 3],
        c: {
            c1: 'string',
            c2: [1, 23, 4]
        },
        d: true,
        e: null,
        f: undefined,
        g: function () {
            console.log('这是 g');
        }
    },
    h: new Date()
};
var reuslt1 = clone(testObj, true);
reuslt1.a.b.push(99);
reuslt1.h.setFullYear(2);
// console.log('reuslt1.h', typeof reuslt1.h, Object.prototype.toString.call(reuslt1.h).slice(8, -1));
console.log('testObj:', testObj);
console.log('result1: ', reuslt1);
var reuslt2 = clone(testObj);
reuslt2.a.b.push(99);
console.log('testObj:', testObj);
console.log('result2: ', reuslt2);
